package com.hycreate.platform.modules.numberinfo;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.hwpf.usermodel.Table;
import org.apache.poi.hwpf.usermodel.TableCell;
import org.apache.poi.hwpf.usermodel.TableIterator;
import org.apache.poi.hwpf.usermodel.TableRow;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.hycreate.platform.common.config.Global;
import com.hycreate.platform.common.persistence.Page;
import com.hycreate.platform.common.utils.DateUtils;
import com.hycreate.platform.common.utils.StringUtils;
import com.hycreate.platform.common.utils.excel.ExportExcel;
import com.hycreate.platform.common.web.BaseController;
import com.hycreate.platform.modules.delay.YhcgDelay;
import com.hycreate.platform.modules.delay.YhcgDelayService;
import com.hycreate.platform.modules.dismissthecase.YhcgDismissthecase;
import com.hycreate.platform.modules.dismissthecase.YhcgDismissthecaseService;
import com.hycreate.platform.modules.handleinfo.YhcgHandleinfo;
import com.hycreate.platform.modules.handleinfo.YhcgHandleinfoService;
import com.hycreate.platform.modules.recheandrejec.YhcgRecheckandrejec;
import com.hycreate.platform.modules.recheandrejec.YhcgRecheckandrejecService;
import com.hycreate.platform.modules.sys.entity.Office;
import com.hycreate.platform.modules.sys.entity.Role;
import com.hycreate.platform.modules.sys.entity.User;
import com.hycreate.platform.modules.sys.service.OfficeService;
import com.hycreate.platform.modules.sys.utils.DictUtils;
import com.hycreate.platform.modules.sys.utils.UserUtils;

import net.sf.json.JSONObject;


/**
 * 工单Controller
 * @author wang
 * @version 2017-11-29
 */
@Controller
@RequestMapping(value = "${adminPath}/numberinfo/yhcgNumberinfo")
public class YhcgNumberinfoController extends BaseController {

	@Autowired
	private YhcgNumberinfoService yhcgNumberinfoService;
	@Autowired
	private YhcgDelayService yhcgDelayService;
	@Autowired 
	private OfficeService officeService;//注入责任单位及督办单位
	@Autowired
	private YhcgHandleinfoService yhcgHandleinfoService;//注入处理记录
	@Autowired
	private YhcgRecheckandrejecService yhcgRecheckandrejecService;//复查记录
	@Autowired
	private YhcgDismissthecaseService yhcgDismissthecaseService;//结案驳回
	@ModelAttribute
	public YhcgNumberinfo get(@RequestParam(required=false) String id) {
		YhcgNumberinfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = yhcgNumberinfoService.get(id);
		}
		if (entity == null){
			entity = new YhcgNumberinfo();
		}
		return entity;
	}
	
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(YhcgNumberinfo yhcgNumberinfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		List<Role> roleList =UserUtils.getRoleList();//查看当前用户角色列表
		String role="";
		User us=UserUtils.getUser();
		for(int i=0;i<roleList.size();i++){
			role+=roleList.get(i).getName()+",";
		}
		if(role.indexOf("瑶海区城管局")>-1){//当为系统管理员
		}else if(role.indexOf("大队用户")>-1){
			yhcgNumberinfo.setPid(us.getOffice().getParentId());//封装当前为大队用户，可查看当前大队下面所有的中队数据
		}else if(role.indexOf("中队用户")>-1){
			yhcgNumberinfo.setResponsibilityunit(us.getOffice().getId());//当前为中队用户
		}
		Office office=new Office();
		office.setType("4");
		List<Office> list=officeService.findListall(office);//查询处理单位,处理单位为中队级
		office.setType("3");
		List<Office> list1=officeService.findListall(office);//查询督办单位，督办单位未大队级
		model.addAttribute("list", list);
		model.addAttribute("list1", list1);
		Page<YhcgNumberinfo> page = yhcgNumberinfoService.findPage(new Page<YhcgNumberinfo>(request, response), yhcgNumberinfo); 
		model.addAttribute("page", page);
		model.addAttribute("us", us);//封装当前用户
		return "modules/numberinfo/yhcgNumberinfoList";
	}
	/**
	 * 信息查询界面
	 */
	
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "listxin")
	public String listxin(YhcgNumberinfo yhcgNumberinfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		List<Role> roleList =UserUtils.getRoleList();//查看当前用户角色列表
		String role="";
		User us=UserUtils.getUser();
		for(int i=0;i<roleList.size();i++){
			role+=roleList.get(i).getName()+",";
		}
		if(role.indexOf("瑶海区城管局")>-1){//当为系统管理员
		}else if(role.indexOf("大队用户")>-1){
			yhcgNumberinfo.setPid(us.getOffice().getParentId());//封装当前为大队用户，可查看当前大队下面所有的中队数据
		}else if(role.indexOf("中队用户")>-1){
			yhcgNumberinfo.setResponsibilityunit(us.getOffice().getId());//当前为中队用户
		}
		Office office=new Office();
		office.setType("4");
		List<Office> list=officeService.findListall(office);//查询处理单位,处理单位为中队级
		office.setType("3");
		List<Office> list1=officeService.findListall(office);//查询督办单位，督办单位未大队级
		model.addAttribute("list", list);
		model.addAttribute("list1", list1);
		Page<YhcgNumberinfo> pa=new Page<YhcgNumberinfo>(request, response);
		pa.setOrderBy("a.timelimit  desc,a.endtime desc");
		Page<YhcgNumberinfo> page = yhcgNumberinfoService.findPage(pa, yhcgNumberinfo); 
		model.addAttribute("page", page);
		model.addAttribute("us", us);//封装当前用户
		return "modules/numberinfo/yhcgxxcx";
	}
	/**
	 * 城管中队界面
	 * @param yhcgNumberinfo
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "listcheng")
	public String listcheng(YhcgNumberinfo yhcgNumberinfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		List<Role> roleList =UserUtils.getRoleList();//查看当前用户角色列表
		String role="";
		User us=UserUtils.getUser();
		for(int i=0;i<roleList.size();i++){
			role+=roleList.get(i).getName()+",";
		}
		if(role.indexOf("瑶海区城管局")>-1&&role.indexOf("瑶海区城管局")>-1){//当为系统管理员
			yhcgNumberinfo.setStatus("0");
		}else if(role.indexOf("大队用户")>-1){
			yhcgNumberinfo.setPid(us.getOffice().getParentId());//封装当前为大队用户，可查看当前大队下面所有的中队数据
			yhcgNumberinfo.setStatus("0");
		}else if(role.indexOf("中队用户")>-1){
			yhcgNumberinfo.setResponsibilityunit(us.getOffice().getId());//当前为中队用户
			yhcgNumberinfo.setStatus("0");
		}
		Office office=new Office();
		office.setType("4");
		List<Office> list=officeService.findListall(office);//查询处理单位,处理单位为中队级
		office.setType("3");
		List<Office> list1=officeService.findListall(office);//查询督办单位，督办单位未大队级
		model.addAttribute("list", list);
		model.addAttribute("list1", list1);		
		Page<YhcgNumberinfo> page = yhcgNumberinfoService.findPage(new Page<YhcgNumberinfo>(request, response), yhcgNumberinfo); 
		model.addAttribute("page", page);
		model.addAttribute("us", us);//封装当前用户


	return "modules/numberinfo/yhcgNumberinfoListcheng";
	}
	@RequestMapping(value = "listy")
	public String listy(YhcgNumberinfo yhcgNumberinfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		return "modules/numberinfo/NewFile";
	}
	
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "form")
	public String form(YhcgNumberinfo yhcgNumberinfo, Model model) {
		Office office=new Office();
		office.setType("4");
		List<Office> list=officeService.findListall(office);//查询处理单位,处理单位为中队级
		office.setType("3");
		List<Office> list1=officeService.findListall(office);//查询督办单位，督办单位未大队级
		User us=UserUtils.getUser();
		model.addAttribute("yhcgNumberinfo", yhcgNumberinfo);
		model.addAttribute("list", list);
		model.addAttribute("list1", list1);
		model.addAttribute("name", yhcgNumberinfo.getFilename());
		model.addAttribute("us", us);//封装当前用户
		return "modules/numberinfo/yhcgNumberinfoForm";
	}

	/**
	 * 工单信息查看
	 * @param yhcgNumberinfo
	 * @param model
	 * @return
	 */
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "formchakan")
	public String formchakan(YhcgNumberinfo yhcgNumberinfo, Model model) {
		Office office=new Office();
		office.setType("4");
		List<Office> list=officeService.findListall(office);//查询处理单位,处理单位为中队级
		office.setType("3");
		List<Office> list1=officeService.findListall(office);//查询督办单位，督办单位未大队级
		User us=UserUtils.getUser();
		model.addAttribute("yhcgNumberinfo", yhcgNumberinfo);
		model.addAttribute("list", list);
		model.addAttribute("list1", list1);
		model.addAttribute("name", yhcgNumberinfo.getFilename());
		model.addAttribute("us", us);//封装当前用户
		return "modules/numberinfo/numbercha";
	}
	
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "numberchakan")
	public String numberchakan(YhcgNumberinfo yhcgNumberinfo, Model model) {
		Office office=new Office();
		office.setType("4");
		List<Office> list=officeService.findListall(office);//查询处理单位,处理单位为中队级
		office.setType("3");
		List<Office> list1=officeService.findListall(office);//查询督办单位，督办单位未大队级
		User us=UserUtils.getUser();
		model.addAttribute("yhcgNumberinfo", yhcgNumberinfo);
		model.addAttribute("list", list);
		model.addAttribute("list1", list1);
		model.addAttribute("name", yhcgNumberinfo.getFilename());
		model.addAttribute("us", us);//封装当前用户
		return "modules/numberinfo/numberzhongcha";
	}
	/**
	 * 结案界面进入
	 * @param yhcgNumberinfo
	 * @param model
	 * @return
	 */
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "formnumberjie")
	public String formnumberjie(YhcgNumberinfo yhcgNumberinfo, Model model) {
		Office office=new Office();
		office.setType("4");
		List<Office> list=officeService.findListall(office);//查询处理单位,处理单位为中队级
		office.setType("3");
		List<Office> list1=officeService.findListall(office);//查询督办单位，督办单位未大队级
		User us=UserUtils.getUser();
		model.addAttribute("yhcgNumberinfo", yhcgNumberinfo);
		model.addAttribute("list", list);
		model.addAttribute("list1", list1);
		model.addAttribute("name", yhcgNumberinfo.getFilename());
		model.addAttribute("us", us);//封装当前用户
		return "modules/numberinfo/numberjie";
	}
	
	@RequestMapping(value = "formcha",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,String> formcha(YhcgNumberinfo yhcgNumberinfo, Model model) {
		yhcgNumberinfo=yhcgNumberinfoService.get(yhcgNumberinfo.getId());
		Map<String,String> map=new HashMap<String,String>();
		map.put("come", DictUtils.getDictLabel(yhcgNumberinfo.getCome(), "come_type", ""));
		map.put("type", DictUtils.getDictLabel(yhcgNumberinfo.getCome(), "type_type", ""));
		map.put("content", yhcgNumberinfo.getContent());
		map.put("remark", yhcgNumberinfo.getRemark());
		return map;
	}
	@RequiresPermissions("numberinfo:yhcgNumberinfo:edit")
	@RequestMapping(value = "save")
	public String save(YhcgNumberinfo yhcgNumberinfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, yhcgNumberinfo)){
			return form(yhcgNumberinfo, model);
		}
		if("".equals(yhcgNumberinfo.getId())){
		yhcgNumberinfo.setCreatetime(new Date());//封装创建时间
		yhcgNumberinfo.setDistributiontime(new Date());//封装派发时间
		String number ="YH"+new Date().getTime()+yhcgNumberinfo.getPhone();
		yhcgNumberinfo.setNumber(number.replaceAll(" ", "").replaceAll("&nbsp;", ""));
		}
		
		yhcgNumberinfo.setName(yhcgNumberinfo.getName().replaceAll(" ", "").replaceAll("&nbsp;", ""));
		yhcgNumberinfo.setPhone(yhcgNumberinfo.getPhone().replaceAll(" ", "").replaceAll("&nbsp;", ""));
		yhcgNumberinfo.setContent(yhcgNumberinfo.getContent().replaceAll(" ", "").replaceAll("&nbsp;", ""));
		yhcgNumberinfo.setStatus("0");//保存为待处理
		yhcgNumberinfoService.save(yhcgNumberinfo);
		addMessage(redirectAttributes, "保存信息成功");
		return "redirect:"+Global.getAdminPath()+"/numberinfo/yhcgNumberinfo/?repage";
	}
	
	@RequiresPermissions("numberinfo:yhcgNumberinfo:edit")
	@RequestMapping(value = "delete")
	public String delete(YhcgNumberinfo yhcgNumberinfo, RedirectAttributes redirectAttributes) {
		yhcgNumberinfoService.delete(yhcgNumberinfo);
		addMessage(redirectAttributes, "删除工单成功");
		return "redirect:"+Global.getAdminPath()+"/numberinfo/yhcgNumberinfo/?repage";
	}
	
	@RequestMapping(value = "file")
	@ResponseBody
	public Map<String,String> uploadfile(YhcgNumberinfo yhcgNumberinfo,HttpServletRequest request, RedirectAttributes redirectAttributes,@RequestParam("file") CommonsMultipartFile file) throws IllegalStateException, IOException {
		Global global = new Global();
		String url1=File.separator + "file"+File.separator+new Date().getTime()+File.separator+file.getOriginalFilename();
		String dir = global.getUserfilesBaseDir()+url1;
        File newFile=new File(dir);
        if (!newFile.getParentFile().exists()) {
			// 如果文件所在的目录不存在，则创建目录
			if (!newFile.getParentFile().mkdirs()) {
				logger.debug("创建文件所在的目录失败!");
			}
		}
        //通过CommonsMultipartFile的方法直接写文件（注意这个时候）
        file.transferTo(newFile);
		Map<String,String> map=new HashMap<String,String>();
		map.put("url", url1);
		map.put("name", file.getOriginalFilename());
		return map;
	}
	
	@RequestMapping(value = "import" , method=RequestMethod.POST)
	public String importfile(YhcgNumberinfo yhcgNumberinfo, RedirectAttributes redirectAttributes,Model model,@RequestParam("file") CommonsMultipartFile file)  {
		  Range buffer;  
		try {  
	            if (file.getOriginalFilename().endsWith(".doc")) {
	                POIFSFileSystem pfs=new POIFSFileSystem(file.getInputStream());
	                HWPFDocument hw=new HWPFDocument(pfs);
	                buffer = hw.getRange();
	                TableIterator it=new TableIterator(buffer);
	                while(it.hasNext()){
	                	Table tb=(Table)it.next();
	                	//迭代行
	                	 for (int i = 0; i < tb.numRows(); i++) {    
	                         TableRow tr = tb.getRow(i);
	                        //迭代列，默认从0开始  
	                        for (int j = 0; j < tr.numCells(); j++) {     
	                             TableCell td = tr.getCell(j);//取得单元格  
	                             //取得单元格的内容  
	                           for(int k=0;k<td.numParagraphs();k++){     
	                                 Paragraph para =td.getParagraph(k);     
	                               /* */
	                                 if(i==0&&j==1){
	                                		 yhcgNumberinfo.setName(para.text().replaceAll("","").trim());
	                                 }
	                                 if(i==1&&j==1){
	                                	 yhcgNumberinfo.setPhone(para.text().replaceAll("","").trim());
	                                 }
	                                 if(i==3&&j==1){
	                                	 yhcgNumberinfo.setContent(para.text().replaceAll("","").trim());
	                                 }
	                                 if(i==4&&j==1){
	                                	 yhcgNumberinfo.setRemark(para.text().replaceAll("","").trim());
	                                 }
	                            } //end for      
	                       }   //end for  
	                     }   //end for  
	                 } //end while  
	            } else if (file.getOriginalFilename().endsWith("docx")) {  
	             /*   OPCPackage opcPackage = POIXMLDocument.openPackage(file.getOriginalFilename());  
	                HWPFDocument hw=new HWPFDocument(is); 
	                buffer = ((XWPFWordExtractor) extractor).getText();  */
	            } else {  
	                System.out.println("此文件不是word文件！");  
	            }  
	  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  
		Office office=new Office();
		office.setType("4");
		List<Office> list=officeService.findListall(office);//查询处理单位,处理单位为中队级
		office.setType("3");
		List<Office> list1=officeService.findListall(office);//查询督办单位，督办单位未大队级
		model.addAttribute("yhcgNumberinfo", yhcgNumberinfo);
		model.addAttribute("list", list);
		model.addAttribute("list1", list1);
		return "modules/numberinfo/yhcgNumberinfoForm" ;
	}
		/**
		 * 任务处置
		 */
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "formdatachu")
	public String formdatachu(YhcgNumberinfo yhcgNumberinfo, Model model,RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, yhcgNumberinfo)){
			return form(yhcgNumberinfo, model);
		}
		/*yhcgNumberinfo.setProcessingtime(new Date());//保存处理时间
*/		yhcgNumberinfo.setStatus("2");//保存正在处理
		yhcgNumberinfoService.save(yhcgNumberinfo);
		addMessage(redirectAttributes, "处理成功");
		return "redirect:"+Global.getAdminPath()+"/numberinfo/yhcgNumberinfo/?repage";
	}
	
	/**
	 * 延期申请提交
	 * @param yhcgNumberinfo
	 * @param time
	 * @param yuan
	 * @param model
	 * @param redirectAttributes
	 * @return
	 */
	@RequestMapping(value = "formdatayan",method=RequestMethod.POST)
	public String formdatayan(YhcgNumberinfo yhcgNumberinfo,@RequestParam String id,@RequestParam String time,@RequestParam String yuan, Model model,RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, yhcgNumberinfo)){
			return form(yhcgNumberinfo, model);
		}
		YhcgDelay yd=new YhcgDelay();
		yd.setExtensiondays(time);//封装延期天数
		yd.setReasonsfodelay(yuan);//封装延期原因
		yd.setUid(id);//封装延期工单id
		yd.setUser(UserUtils.getUser().getId());//封装申请人id
		yd.setStatus("0");//封装延期申请状态为待审核
		yd.setYantime(new Date());
		yhcgDelayService.save(yd);
		addMessage(redirectAttributes, "延期申请已提交");
		return "redirect:"+Global.getAdminPath()+"/numberinfo/yhcgNumberinfo/listcheng?repage";
	}
	
	/**
	 * 任务处置界面跳转
	 */
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "formdatarenchu")
	public String formchuren(YhcgNumberinfo yhcgNumberinfo, Model model) {	
		User us=UserUtils.getUser();
		model.addAttribute("yhcgNumberinfo", yhcgNumberinfo);
		model.addAttribute("name", yhcgNumberinfo.getFilename());
		model.addAttribute("us", us);//封装当前用户
		return "modules/numberinfo/yhcgNumberinfochuForm";
	}
	
	/**
	 * 任务处置提交
	 * @param yhcgNumberinfo
	 * @param model
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "formdatachusave")
	public String formchusave(YhcgNumberinfo yhcgNumberinfo, Model model,RedirectAttributes redirectAttributes) {	
		YhcgHandleinfo yhcghandleinfo =new YhcgHandleinfo();
		yhcghandleinfo.setUid(yhcgNumberinfo.getId());//封装工单id
		yhcghandleinfo.setProcessingtime(new Date());//封装处理时间
		yhcghandleinfo.setProcessingtunit(yhcgNumberinfo.getChuuser());//处理人
		yhcghandleinfo.setProcessingtremark(yhcgNumberinfo.getContentchu());//封装处理结果
		yhcghandleinfo.setFilechuname(yhcgNumberinfo.getFilechuname());//封装图片名
		yhcghandleinfo.setFiletuurl(yhcgNumberinfo.getFiletuurl());//封装图片地址
		yhcgHandleinfoService.save(yhcghandleinfo);//写入处理记录
		yhcgNumberinfo.setEndtime(new Date());
		yhcgNumberinfo.setStatus("2");//封装为待复核
		yhcgNumberinfoService.save(yhcgNumberinfo);
		addMessage(redirectAttributes, "处理成功");
	return "redirect:"+Global.getAdminPath()+"/numberinfo/yhcgNumberinfo/listcheng?repage";
	}
	
	/**
	 * 复查列表
	 */
	
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "listchengfu")
	public String listchengfu(YhcgNumberinfo yhcgNumberinfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		User us=UserUtils.getUser();
		yhcgNumberinfo.setStatus("2");
		Office office=new Office();
		office.setType("4");
		List<Office> list=officeService.findListall(office);//查询处理单位,处理单位为中队级
		office.setType("3");
		List<Office> list1=officeService.findListall(office);//查询督办单位，督办单位未大队级
		model.addAttribute("list", list);
		model.addAttribute("list1", list1);
		Page<YhcgNumberinfo> page = yhcgNumberinfoService.findPage(new Page<YhcgNumberinfo>(request, response), yhcgNumberinfo); 
		model.addAttribute("page", page);
		model.addAttribute("us", us);//封装当前用户
	return "modules/numberinfo/yhcgNumberinfoListfu";
	}
	/**
	 * 结案分析列表
	 * @param yhcgNumberinfo
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "listjie")
	public String listjie(YhcgNumberinfo yhcgNumberinfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		User us=UserUtils.getUser();
		yhcgNumberinfo.setStatus("3");//查询为待结案列表
		Office office=new Office();
		office.setType("4");
		List<Office> list=officeService.findListall(office);//查询处理单位,处理单位为中队级
		office.setType("3");
		List<Office> list1=officeService.findListall(office);//查询督办单位，督办单位未大队级
		model.addAttribute("list", list);
		model.addAttribute("list1", list1);
		Page<YhcgNumberinfo> page = yhcgNumberinfoService.findPage(new Page<YhcgNumberinfo>(request, response), yhcgNumberinfo); 
		model.addAttribute("page", page);
		model.addAttribute("us", us);//封装当前用户
	return "modules/numberinfo/yhcgNumberinfoListjie";
	}
	/**
	 * 已结案分析列表
	 * @param yhcgNumberinfo
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "listjieyi")
	public String listjieyi(YhcgNumberinfo yhcgNumberinfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		User us=UserUtils.getUser();
		yhcgNumberinfo.setStatus("4");//查询为待结案列表
		Office office=new Office();
		office.setType("4");
		List<Office> list=officeService.findListall(office);//查询处理单位,处理单位为中队级
		office.setType("3");
		List<Office> list1=officeService.findListall(office);//查询督办单位，督办单位未大队级
		model.addAttribute("list", list);
		model.addAttribute("list1", list1);
		Page<YhcgNumberinfo> page = yhcgNumberinfoService.findPage(new Page<YhcgNumberinfo>(request, response), yhcgNumberinfo); 
		model.addAttribute("page", page);
		model.addAttribute("us", us);//封装当前用户
	return "modules/numberinfo/yhcgNumberinfoListjieyi";
	}
	
	/**
	 * 城管局复核
	 * @param yhcgNumberinfo
	 * @param model
	 * @param redirectAttributes
	 * @return
	 */
	@RequestMapping(value = "formchufut")
	public String formchufut(YhcgNumberinfo yhcgNumberinfo, Model model,RedirectAttributes redirectAttributes) {	
		YhcgRecheckandrejec yhcgRecheckandrejec =new YhcgRecheckandrejec();
		yhcgRecheckandrejec.setUid(yhcgNumberinfo.getId());//封装工单id
		yhcgRecheckandrejec.setStatus(yhcgNumberinfo.getFuhestatus());//封装审核状态	
		yhcgRecheckandrejec.setReviewuser(yhcgNumberinfo.getChuuser());//封装复查人
		yhcgRecheckandrejec.setReviewproposal(yhcgNumberinfo.getContentchu());//封装复查建议
		yhcgRecheckandrejec.setReviewtime(new Date());
		yhcgRecheckandrejecService.save(yhcgRecheckandrejec);//写入复查记录记录
		if(yhcgNumberinfo.getFuhestatus().equals("1")){
			yhcgNumberinfo.setStatus("3");//封装为待结案			
		}else{
			yhcgNumberinfo.setStatus("0");//打回为待处理	
		}
		yhcgNumberinfoService.save(yhcgNumberinfo);
		addMessage(redirectAttributes, "复核成功");
	return "redirect:"+Global.getAdminPath()+"/numberinfo/yhcgNumberinfo/listchengfu?repage";
	}
	
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "formnumberjietong")
	public String formnumberjietong(YhcgNumberinfo yhcgNumberinfo, Model model) {
		YhcgDismissthecase yhcgDismissthecase =new YhcgDismissthecase();
		yhcgDismissthecase.setUid(yhcgNumberinfo.getId());
		yhcgDismissthecase.setCloseduser(yhcgNumberinfo.getChuuser());//封装结案人
		yhcgDismissthecase.setClosedproposal(yhcgNumberinfo.getContentchu());//封装结案建议
		yhcgDismissthecase.setClosedtime(new Date());//封装结案时间
		yhcgDismissthecase.setStatus("1");
		yhcgDismissthecase.setIsnot(yhcgNumberinfo.getFuhestatus());//封装是否重复投诉
		yhcgDismissthecaseService.save(yhcgDismissthecase);//添加结案记录
		yhcgNumberinfo.setStatus("4");//封装为已结案
		yhcgNumberinfo.setEndtime(new Date());
		yhcgNumberinfoService.save(yhcgNumberinfo);
		return "redirect:"+Global.getAdminPath()+"/numberinfo/yhcgNumberinfo/listjie?repage";
	}
	
	@RequiresPermissions("numberinfo:yhcgNumberinfo:view")
	@RequestMapping(value = "formnumberjiebo")
	public String formnumberjiebo(YhcgNumberinfo yhcgNumberinfo, Model model) {
		YhcgDismissthecase yhcgDismissthecase =new YhcgDismissthecase();
		yhcgDismissthecase.setUid(yhcgNumberinfo.getId());
		yhcgDismissthecase.setCloseduser(yhcgNumberinfo.getChuuser());//封装结案人
		yhcgDismissthecase.setClosedproposal(yhcgNumberinfo.getContentchu());//封装结案建议
		yhcgDismissthecase.setClosedtime(new Date());//封装结案时间
		yhcgDismissthecase.setStatus("2");
		yhcgDismissthecaseService.save(yhcgDismissthecase);//添加结案记录
		yhcgNumberinfo.setStatus("0");//封装为待处理
		if(yhcgNumberinfo.getTimelimitgai()!=null){
		yhcgNumberinfo.setTimelimit(yhcgNumberinfo.getTimelimitgai());
		}
		yhcgNumberinfoService.save(yhcgNumberinfo);
		return "redirect:"+Global.getAdminPath()+"/numberinfo/yhcgNumberinfo/listjie?repage";
	}
	/**
	 * 文件下载
	 * @param url
	 * @param request
	 * @param response
	 * @throws MalformedURLException
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "upload",method = RequestMethod.GET)
	@ResponseBody
	public void upload(String url, HttpServletRequest request, HttpServletResponse response) throws MalformedURLException, UnsupportedEncodingException { // path是指欲下载的文件的路径。
		YhcgHandleinfo yhcghandleinfo =new YhcgHandleinfo();
		yhcghandleinfo=yhcgHandleinfoService.get(url);
		Global global = new Global();
    	 
        // 读到流中
        InputStream inStream=null;
    	String  url2 = URLEncoder.encode(yhcghandleinfo.getFilechuname(),"UTF-8");
		try {
			inStream = new FileInputStream(global.getUserfilesBaseDir()+yhcghandleinfo.getFiletuurl());
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}// 文件的存放路径
        // 设置输出的格式
        response.reset();
        response.setContentType("bin");
        response.addHeader("Content-Disposition", "attachment; filename="+url2);
        // 循环取出流中的数据
        byte[] b = new byte[2048];
        int len;
        try {
            while ((len = inStream.read(b)) > 0)
                response.getOutputStream().write(b, 0, len);
            inStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	/**
	 * 图片回显
	 * @param url
	 * @param request
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping(value = "uploadhuixian",method = RequestMethod.GET)
	@ResponseBody
	public void uploadhuixian(String url, HttpServletRequest request, HttpServletResponse response) throws IOException { // path是指欲下载的文件的路径。
		/*YhcgHandleinfo yhcghandleinfo =new YhcgHandleinfo();*/
		YhcgHandleinfo yhcghandleinfo=yhcgHandleinfoService.get(url);
		Global global = new Global();
		   ServletOutputStream out = null;  
	        FileInputStream ips = null;  
	        try {  
	            //获取图片存放路径  
	            ips = new FileInputStream(new File(global.getUserfilesBaseDir()+yhcghandleinfo.getFiletuurl()));  
	            response.setContentType("multipart/form-data");  
	            out = response.getOutputStream();  
	            //读取文件流  
	            int len = 0;  
	            byte[] buffer = new byte[1024 * 10];  
	            while ((len = ips.read(buffer)) != -1){  
	                out.write(buffer,0,len);  
	            }  
	            out.flush();  
	        }catch (Exception e){  
	            e.printStackTrace();  
	        }finally {  
	            out.close();  
	            ips.close();  
	        }  
       /* // 读到流中
        InputStream inStream=null;
    	String  url2 = URLEncoder.encode(yhcghandleinfo.getFilechuname(),"UTF-8");
		try {
			inStream = new FileInputStream(global.getUserfilesBaseDir()+yhcghandleinfo.getFiletuurl());
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}// 文件的存放路径
        // 设置输出的格式
        response.reset();
        response.setContentType("bin");
        response.addHeader("Content-Disposition", "attachment; filename="+url2);
        // 循环取出流中的数据
        byte[] b = new byte[2048];
        int len;
        try {
            while ((len = inStream.read(b)) > 0)
              response.getOutputStream().write(b, 0, len);
            response.getOutputStream().flush();
        } catch (IOException e) {
            e.printStackTrace();
        }*/
	}
	/**
	 * 导出工单数据
	 * @param user
	 * @param request
	 * @param response
	 * @param redirectAttributes
	 * @return
	 */
		@RequestMapping(value = "export", method=RequestMethod.GET)
	    public String exportFile(YhcgNumberinfo yhcgNumberinfo,String uid, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		 yhcgNumberinfo.setUid(uid);//封装选择的工单数据
			try {
	            String fileName = "工单数据"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
	            Page<YhcgNumberinfo> page = yhcgNumberinfoService.findPage(new Page<YhcgNumberinfo>(request, response, -1), yhcgNumberinfo);
	    		new ExportExcel("工单数据", YhcgNumberinfo.class).setDataList(page.getList()).write(response, fileName).dispose();
	    		return null;
			} catch (Exception e) {
				addMessage(redirectAttributes, "导出用户失败！失败信息："+e.getMessage());
			}
			return "redirect:" + adminPath + "/numberinfo/yhcgNumberinfo/listxin?repage";
	    }
		
		@RequestMapping(value = "datafrom")
		@ResponseBody
		public String datasave( HttpServletRequest request,Model model, RedirectAttributes redirectAttributes) {
			BufferedReader jsonStr;
			Json js=new Json();
				try {
					jsonStr = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream(),"UTF-8")); 
					StringBuffer sb = new StringBuffer("");
					String temp;
					while ((temp = jsonStr.readLine()) != null) {
		                sb.append(temp);
							}
					jsonStr.close();
					String params = sb.toString();//根据输入流转化为字符串
					JSONObject jsonObj= JSONObject.fromObject(params); //把字符串转化为json对象
					YhcgNumberinfo yhcgNumberinfo =new YhcgNumberinfo();
					yhcgNumberinfo.setCreatetime(new Date());//封装创建时间
					/*yhcgNumberinfo.setDistributiontime(new Date());//封装派发时间
*/					String number ="YH"+new Date().getTime()+yhcgNumberinfo.getPhone();
					yhcgNumberinfo.setNumber(number.replaceAll(" ", "").replaceAll("&nbsp;", ""));
					yhcgNumberinfo.setName(yhcgNumberinfo.getName().replaceAll(" ", "").replaceAll("&nbsp;", ""));
					yhcgNumberinfo.setPhone(yhcgNumberinfo.getPhone().replaceAll(" ", "").replaceAll("&nbsp;", ""));
					yhcgNumberinfo.setContent(yhcgNumberinfo.getContent().replaceAll(" ", "").replaceAll("&nbsp;", ""));
					yhcgNumberinfo.setStatus("0");//保存为待处理
					yhcgNumberinfoService.save(yhcgNumberinfo);
					js.setCode("2");
					js.setSusscess("true");
					}catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					js.setCode("1");
					js.setSusscess("false");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					js.setCode("1");
					js.setSusscess("false");
				}
				JSONObject rsp=JSONObject.fromObject(js);
			return rsp.toString();
		}
		
		@RequestMapping(value = "listweichu")
		@ResponseBody
		public  Map<String,Integer> listweichu(HttpServletRequest request, HttpServletResponse response, Model model) {
			Map<String,Integer> map=new HashMap<String,Integer>();
			YhcgDelay yhcgDelay=new YhcgDelay();
			yhcgDelay.setStatus("0");
			map.put("yan",yhcgDelayService.findList(yhcgDelay).size());
			YhcgNumberinfo yhcgNumberinfojie =new YhcgNumberinfo();
			yhcgNumberinfojie.setStatus("3");//查询为待结案列表
			map.put("jie", yhcgNumberinfoService.findList(yhcgNumberinfojie).size());
			YhcgNumberinfo yhcgNumberinfofu =new YhcgNumberinfo();
			yhcgNumberinfofu.setStatus("2");
			map.put("fu", yhcgNumberinfoService.findList(yhcgNumberinfofu).size());
			YhcgNumberinfo yhcgNumberinfochu =new YhcgNumberinfo();
			List<Role> roleList =UserUtils.getRoleList();//查看当前用户角色列表
			String role="";
			User us=UserUtils.getUser();
			for(int i=0;i<roleList.size();i++){
				role+=roleList.get(i).getName()+",";
			}
			if(role.indexOf("瑶海区城管局")>-1&&role.indexOf("瑶海区城管局")>-1){//当为系统管理员
				yhcgNumberinfochu.setStatus("0");
			}else if(role.indexOf("大队用户")>-1){
				yhcgNumberinfochu.setPid(us.getOffice().getParentId());//封装当前为大队用户，可查看当前大队下面所有的中队数据
				yhcgNumberinfochu.setStatus("0");
			}else if(role.indexOf("中队用户")>-1){
				yhcgNumberinfochu.setResponsibilityunit(us.getOffice().getId());//当前为中队用户
				yhcgNumberinfochu.setStatus("0");
			}
			map.put("chu", yhcgNumberinfoService.findList(yhcgNumberinfochu).size());
			return map;
		}
}